import requests

from common.log_utils import init_logger
from config import BASE_URL
logger=init_logger()


class EmployeeApi(object):
    base_path = "/api/sys/user/"

    @classmethod
    def add_emp(cls, headers, body):
        url = BASE_URL + cls.base_path
        logger.debug(f'url:{url}')
        logger.debug(f'请求头:{headers}')
        logger.debug(f'请求体:{body}')
        return requests.post(url=url, headers=headers, json=body)

    @classmethod
    def query_emp(cls, user_id, headers):
        url = BASE_URL + cls.base_path + user_id
        logger.debug(f'url:{url}')
        logger.debug(f'员工id:{user_id}')
        return requests.get(url, headers=headers)

    @classmethod
    def modify_emp(cls, user_id, headers, body):
        url = BASE_URL + cls.base_path + user_id
        logger.debug(f'url:{url}')
        logger.debug(f'请求头:{headers}')
        logger.debug(f'请求体:{body}')
        return requests.put(url=url, headers=headers, json=body)

    @classmethod
    def del_emp(cls, user_id, headers):
        url = BASE_URL + cls.base_path + user_id
        logger.debug(f'url:{url}')
        logger.debug(f'员工id:{user_id}')
        return requests.delete(url=url, headers=headers)
